import storage from '@/utils/storage'

const app = {
  state: {
    code: 'DEMO',
    version: '1.0.0',
    device: 'desktop',
    size: 'small',
    router: {},
    sideWidth: 240,
    showDashboard: true,
    showHeaderMenu: false,
    showLeftMenu: true,
    showTags: false,
    headerMenu: storage.getSession('headerMenu')
  },
  mutations: {
    TOGGLE_DEVICE: (state, device) => {
      state.device = device
    },
    SET_ROUTER: (state, router) => {
      state.router = router
    },
    SET_COLLAPSE: (state, action) => {
      state.isCollapse = !state.isCollapse
    },
    SET_SIDEWIDTH: (state, sideWidth) => {
      state.sideWidth = sideWidth
    },
    SET_HEADERMENU: (state, name) => {
      storage.setSession('headerMenu', name)
      state.headerMenu = name
    },
    SET_SHOW_TAGS: (state, flag) => {
      state.showTags = flag
    }
  },
  actions: {
    toggleDevice ({ commit }, device) {
      commit('TOGGLE_DEVICE', device)
    },
    setRouter ({ commit }, router) {
      commit('SET_ROUTER', router)
    }
  }
}

export default app
